package com.example.vpdemo;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.google.android.material.bottomnavigation.BottomNavigationItemView;

import java.util.ArrayList;


public class FragmentA extends Fragment {

    View view;
    private RecyclerView rl;
    boolean ischagnge;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        if (view == null) {
            view = inflater.inflate(R.layout.fragment_a, container, false);
        }
        if (ischagnge) {
            initView( ischagnge,view);
            ischagnge=false;
        }else {

            ischagnge=true;
        }

        return view;
    }

    private void initView(boolean ischagnge,View view) {
        rl = (RecyclerView) view.findViewById(R.id.rl);

        final ArrayList<String> strings = new ArrayList<>();
        MyAdapter adapter = new MyAdapter(getContext(), strings);
        for (int i = 0; i < 50; i++) {
            if (ischagnge) {
                strings.add("change" + i + "ge ");
                ischagnge=false;


                LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()) ;

                rl.setLayoutManager(layoutManager);

                rl.setAdapter(adapter);
            }else {
                strings.add("" + i + "");
                ischagnge=true;

                LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()) ;

                rl.setLayoutManager(layoutManager);

                rl.setAdapter(adapter);
            }

        }



        adapter.setOnClick(new MyAdapter.PassPosition() {
            @Override
            public void pass(int position) {
//                startActivity(new Intent(getActivity(), Main2Activity.class));
//                Toast.makeText(getActivity(), ""+strings.get(position), Toast.LENGTH_SHORT).show();
                BottomPopWinDow2 bottomPopWinDow=new BottomPopWinDow2(getContext());
                bottomPopWinDow.show();
            }
        });

    }
}
